home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWCollec / Include / FWOrdCol.h < prev   
Encoding:
C/C++ Source or Header  |  1995-11-08  |  5.8 KB  |  182 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FWOrdCol.h
  3.  
  4.     Contains:    Definition of class FW_CPrivOrderedCollection
  5.  
  6.     Written by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1993-94 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <1>    10/24/94    jpa        first checked in
  13.          <6>     6/20/94    RR        ODMemoryHeap* -> ODMemoryHeapID
  14.          <5>     6/14/94    RR        Added forward declaration ODMemoryHeap
  15.          <4>      6/9/94    RR        Remove ASLM stuff
  16.          <2>     5/10/94    RR        Removed ASLM_COMPATIBLE/CDECL
  17.          <1>      5/5/94    CG        first checked in
  18.          <9>     3/15/94    MB        Changes to support SCpp/ASLM builds,
  19.                                     #1150864.
  20.          <8>      2/9/94    TÇ        add a couple of explicit "virtual" to the
  21.                                     class declaration to pacify ASLM
  22.          <7>      2/7/94    JA        Tiger Team Makeover!
  23.          <6>      2/2/94    NP        Added support for allocating internal
  24.                                     structures in given heap.
  25.          <5>     12/7/93    NP        Added helpful comments, because PEOPLE
  26.                                     AREN'T COMMENTING HEADER FILES!!!!!
  27.          <4>    11/19/93    PH        ASLM fix - add class id for FW_CPrivValueLink
  28.          <3>    11/19/93    NP        Add definition of FW_CPrivValueLink to here (to
  29.                                     allow subclassing.)
  30.          <1>     8/13/93    RCR        first checked in
  31.  
  32.     To Do:
  33. */
  34.  
  35. #ifndef FWORDCOL_H
  36. #define FWORDCOL_H
  37.  
  38. #ifndef FWLIST_H
  39. #include "FWList.h"
  40. #endif
  41.  
  42. #if FW_LIB_EXPORT_PRAGMAS
  43. #pragma lib_export on
  44. #endif
  45.  
  46. //==============================================================================
  47. // Theory of Operation
  48. //==============================================================================
  49.  
  50. // OrdereCollection is an ordered collection of elements of type void* (since
  51. // we can't use templates)
  52. // Duplicates are allowed.
  53.  
  54. //==============================================================================
  55. // Constants
  56. //==============================================================================
  57.  
  58. //==============================================================================
  59. // Scalar Types
  60. //==============================================================================
  61.  
  62. typedef void* FW_ElementType;
  63.  
  64. //=====================================================================================
  65. // Classes defined in this interface
  66. //=====================================================================================
  67.  
  68. class FW_CLASS_ATTR FW_CPrivOrderedCollection;    // An ordered (not sorted) collection of ElementTypes
  69. class FW_CLASS_ATTR FW_COrderedCollectionIterator;
  70.  
  71. //=====================================================================================
  72. // Classes used by this interface
  73. //=====================================================================================
  74.  
  75. class FW_CLASS_ATTR FW_CPrivValueLink;             // A link plus a value of type FW_ElementType.
  76.  
  77. //=====================================================================================
  78. // Global Variables
  79. //=====================================================================================
  80.  
  81. //=====================================================================================
  82. // Class FW_CPrivValueLink - Definition
  83. //=====================================================================================
  84.  
  85. class FW_CLASS_ATTR FW_CPrivValueLink : public FW_CPrivLink {
  86.     
  87. public:
  88.                             FW_CPrivValueLink(FW_ElementType value);        
  89.     virtual                ~FW_CPrivValueLink();
  90.     FW_ElementType                GetValue()                        { return fValue;}
  91.     void                    SetValue(FW_ElementType v)            { fValue = v;}
  92.  
  93. private:
  94.     FW_ElementType         fValue;
  95. };
  96.  
  97. //=====================================================================================
  98. // Class FW_CPrivOrderedCollection
  99. //=====================================================================================
  100.  
  101. class FW_CLASS_ATTR FW_CPrivOrderedCollection
  102. {
  103.     
  104. public:
  105.  
  106.     FW_CPrivOrderedCollection();
  107.     FW_CPrivOrderedCollection(void* where);
  108.     virtual ~FW_CPrivOrderedCollection();
  109.  
  110.     unsigned long         Count() const             { return fImplementation.Count(); };
  111.     
  112.     virtual void    AddFirst(FW_ElementType element);
  113.     virtual void    AddLast(FW_ElementType element);
  114.     virtual void    AddBefore(FW_ElementType existing, FW_ElementType tobeadded);
  115.     virtual void    AddAfter(FW_ElementType existing, FW_ElementType tobeadded);
  116.  
  117.     virtual FW_ElementType    After(FW_ElementType existing);
  118.     virtual FW_ElementType    Before(FW_ElementType existing);
  119.  
  120.     virtual FW_ElementType    First();
  121.         // Returns kODNULL if there is no first element.
  122.     virtual FW_ElementType    Last();
  123.  
  124.     virtual FW_ElementType    RemoveFirst();
  125.         // Don't call if there are no elements. Crash will result.
  126.     virtual FW_ElementType    RemoveLast();
  127.     virtual void    RemoveAll();
  128.     
  129.         // Called from the destructor. Removes all elements, deleting the links
  130.         // Does not delete the elements themselves
  131.  
  132. /*    
  133.     // Too dangerous because elements destructor is not called    
  134.     virtual void    DeleteAll();
  135.     
  136.         // Removes and deletes all elements
  137. */
  138.         
  139.     virtual void    Remove(FW_ElementType existing);
  140.     virtual FW_Boolean    Contains(FW_ElementType existing);
  141.     
  142.     virtual FW_COrderedCollectionIterator* CreateIterator();
  143.  
  144. protected:
  145.      virtual FW_CPrivValueLink*     CreateNewLink(FW_ElementType value) const;
  146.      virtual FW_Boolean    ElementsMatch(FW_ElementType v1,FW_ElementType v2) const;
  147.          // Does a pointer comparison by default 
  148.  
  149. private:
  150.     FW_CPrivLinkedList        fImplementation;
  151.     void*            fHeap;
  152. //    ODMemoryHeapID    fHeap;                 // if kODNULL, use default heap.
  153.  
  154.     friend class FW_COrderedCollectionIterator;
  155.     friend class ListIterator;
  156. };
  157.  
  158. //=====================================================================================
  159. // Class FW_COrderedCollectionIterator
  160. //=====================================================================================
  161.  
  162. class FW_CLASS_ATTR FW_COrderedCollectionIterator {
  163. public:
  164.     FW_COrderedCollectionIterator(FW_CPrivOrderedCollection* collection);
  165.     ~FW_COrderedCollectionIterator();
  166.     FW_ElementType    First();
  167.     FW_ElementType    Next();
  168.     FW_ElementType    Last();
  169.     FW_ElementType    Previous();
  170.     FW_Boolean    IsNotComplete();
  171.     
  172. private:
  173.       FW_CPrivOrderedCollection*    fCollection;
  174.     FW_CPrivLinkedListIterator    fImplementation;
  175. };
  176.  
  177. #if FW_LIB_EXPORT_PRAGMAS
  178. #pragma lib_export off
  179. #endif
  180.  
  181. #endif // FWORDCOL_H
  182.